﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HoneyBadgersOfficePlayer.Models;
using System.Data;

namespace HoneyBadgersOfficePlayer.Views
{
    public partial class Admin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<SqlParameter> parameterList = new List<SqlParameter>();
                SqlDataReader reader = SQLUtilities.RunStoredProcedure("GetAllUsers", parameterList);

                if (reader != null)
                {
                    DataTable dt = new DataTable();
                    BoundField bf = new BoundField();
                    BoundField bf1 = new BoundField();
                 
                    dt.Columns.Add("UserID");
                    dt.Columns.Add("User Name");

                    while (reader.Read())
                    {
                        string userID = reader[0].ToString();
                        string username = reader[1].ToString();
                        
                        dt.Rows.Add(
                            bf1.DataField.Insert(0, userID),
                            bf.DataField.Insert(0, username)
                        );

                    }
                    Session["CACHEDATA1"] = dt;
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }

                parameterList.Clear();
                SqlDataReader reader2 = SQLUtilities.RunStoredProcedure("GetAllSongsAndArtists", parameterList);

                if (reader2 != null)
                {
                    DataTable dt = new DataTable();
                    BoundField bf = new BoundField();
                    BoundField bf1 = new BoundField();

                    dt.Columns.Add("Artist");
                    dt.Columns.Add("Song Title");

                    while (reader2.Read())
                    {
                        string artist = reader2[0].ToString();
                        string song = reader2[1].ToString();

                        dt.Rows.Add(
                            bf1.DataField.Insert(0, artist),
                            bf.DataField.Insert(0, song)
                        );
                    }
                    Session["CACHEDATA1"] = dt;
                    GridView2.DataSource = dt;
                    GridView2.DataBind();
                }
            }
        }
    }
}